package net.caixiaomi.info.ui.discovery;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import net.caixiaomi.info.R;
import net.caixiaomi.info.base.BaseFragment;
import net.caixiaomi.info.base.quickadapter.BaseQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.base.quickadapter.entity.MultiItemEntity;
import net.caixiaomi.info.interfaces.ComonFragmentImpl;
import net.caixiaomi.info.model.DIPlayerEntity;
import net.caixiaomi.info.model.DIPlayerInfo;
import net.caixiaomi.info.model.TeamDetailFutureMatch;
import net.caixiaomi.info.model.TeamMatchInfo;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by mac on 2018/9/11.
 */

public class TeamPersonFutureFragment extends BaseFragment implements ComonFragmentImpl {

    @BindView(android.R.id.list)
    RecyclerView mListView;
    @BindView(R.id.no_data_tv)
    TextView mNoData;

    View headerView;

    private LeagueTeamAdapter mAdapter;

    private TeamDetailFutureMatch entity;

    @Override
    public void setType(int type) {

    }

    @Override
    public void setFilter(String filter) {

    }

    @Override
    protected int fragmentLayout() {
        return R.layout.league_shooter_layout;
    }

    @Override
    protected void onFragmentCreated(View view, @Nullable Bundle savedInstanceState) {
        mListView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mAdapter = new LeagueTeamAdapter(R.layout.team_person_future_item);
        mListView.setAdapter(mAdapter);
        headerView=View.inflate(getActivity(),R.layout.team_person_future_layout,null);
        mAdapter.addHeaderView(headerView);

        mNoData.setVisibility(View.VISIBLE);
        headerView.setVisibility(View.GONE);
    }

    public void initData(TeamDetailFutureMatch entity) {
        this.entity = entity;
        List<TeamMatchInfo> matchInfoFutureList=entity.getMatchInfoFutureList();
        if(matchInfoFutureList.size()==0){
            mNoData.setVisibility(View.VISIBLE);
            mListView.setVisibility(View.GONE);
            return;
        }
        headerView.setVisibility(View.VISIBLE);
        mNoData.setVisibility(View.GONE);
        List<MultiItemEntity>data=new ArrayList<>();
        data.addAll(matchInfoFutureList);
        mAdapter.setNewData(data);
    }

    public class LeagueTeamAdapter extends BaseQuickAdapter<MultiItemEntity, BaseViewHolder> {

        public LeagueTeamAdapter(int layoutResId) {
            super(layoutResId);
        }

        @Override
        protected void convert(BaseViewHolder helper, MultiItemEntity item) {
            try {
                TeamMatchInfo hall = (TeamMatchInfo) item;
                helper.setText(R.id.host_name, hall.gethTeam());
                helper.setText(R.id.visitor_name, hall.getvTeam());
                helper.setText(R.id.match_date, hall.getDate());
                helper.setText(R.id.match_name, hall.getMatchName());
            }catch (Exception e){

            }
        }
    }
}
